import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:material_collection_app/utils/utils.dart';

class ListCard extends StatefulWidget {
  final Map item;
  final ValueChanged<int> buttonOnTap;

  ListCard({Key key, this.item, this.buttonOnTap}) : super(key: key);

  @override
  State<StatefulWidget> createState() => MyState();
}

class MyState extends State<ListCard> {
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);
    Map item = widget.item;

    return Container(
        width: 500.w,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(20.w),
        ),
        margin: EdgeInsets.fromLTRB(25.w, 20.w, 25.w, 0.w),
        child: InkWell(
            onTap: () {
              if (item['cardRoute'] != null) {
                Navigator.pushNamed(context, item['cardRoute']);
              }
            },
            onTapDown: (details) {
              FocusScope.of(context).requestFocus(FocusNode());
            },
            child: Column(children: <Widget>[
              Container(
                alignment: Alignment.center,
                height: 90.w,
                padding: EdgeInsets.fromLTRB(24.w, 0, 24.w, 0.w),
                decoration: BoxDecoration(
                  color: Utils.hexToColor(item['headColor']),
                  borderRadius:
                      BorderRadius.vertical(top: Radius.circular(20.w)),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Image.asset(item['icon'] ?? 'assets/rk.png',
                            width: 40.w),
                        Container(
                          margin: EdgeInsets.only(left: 10.w),
                          child: Text(
                            item['title'],
                            style: TextStyle(
                                color: Color(0xFF666666),
                                fontSize: 14,
                                height: 1),
                          ),
                        )
                      ],
                    ),
                    Text(
                      item['statusText'],
                      style: TextStyle(
                          color: Utils.hexToColor(item['statusColor']),
                          fontSize: 14),
                    )
                  ],
                ),
              ),
              Container(
                  height: 180.w,
                  alignment: Alignment.topLeft,
                  padding: EdgeInsets.fromLTRB(24.w, 30.w, 24.w, 0.w),
                  child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start, // 左对齐
                          children: <Widget>[
                            Text(item['cardTitle'],
                                style: TextStyle(
                                    color: Color(0xFF333333),
                                    fontSize: 15,
                                    fontWeight: FontWeight.bold,
                                    height: 1)),
                            Container(
                              margin: EdgeInsets.only(top: 22.w),
                              child: Text(item['cardSubText1'],
                                  style: TextStyle(
                                      color: Color(0xFF666666),
                                      fontSize: 12,
                                      height: 1)),
                            ),
                            Container(
                              margin: EdgeInsets.only(top: 13.w),
                              child: Text(item['cardSubText2'],
                                  style: TextStyle(
                                      color: Color(0xFF666666),
                                      fontSize: 12,
                                      height: 1)),
                            ),
                          ],
                        ),
                        Offstage(
                            offstage: item['btnText'] == '' ? true : false,
                            child: SizedBox(
                                width: 160.w,
                                height: 66.w,
                                child: ElevatedButton(
                                  onPressed: () {
                                    widget.buttonOnTap(item['status']);
                                  },
                                  child: Text(
                                    item['btnText'],
                                    style: TextStyle(color: Colors.white),
                                  ),
                                  style: ElevatedButton.styleFrom(
                                      padding:
                                          EdgeInsets.symmetric(horizontal: 0),
                                      backgroundColor: Utils.hexToColor(
                                          item['btnColor'] ?? '#FFFFFF'),
                                      shape: RoundedRectangleBorder(
                                          borderRadius: BorderRadius.all(
                                              Radius.circular(8.w)))),
                                )))
                      ]))
            ])));
  }
}
